package io;

import java.io.*;
/**
 * 缓冲字节流:加快读写速度
 * 使用缓冲字节流完成文件复制
 */
public class CopyDemo3 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("001.png");         //文件输入流，低级流
        BufferedInputStream bis = new BufferedInputStream(fis);             //缓冲输入流，高级流
        FileOutputStream fos = new FileOutputStream("000001.png");    //文件输出流，低级流
        BufferedOutputStream bos = new BufferedOutputStream(fos);           //缓冲输出流，高级流
        long start = System.currentTimeMillis();
        int d;
        while ((d = bis.read()) != -1) {
            bos.write(d);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕，耗时"+(end - start)+"毫秒");
        bis.close();    //关闭高级流时，顺便关闭低级流
        bos.close();
    }
}
